﻿using Api.Application.Command.Menu;
using Api.DTO;
using ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    /// <summary>
    /// 菜单控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class MenuController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> AddMenu(AddMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<MenuDTO>> GetMenu([FromQuery]GetMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取父级下拉框
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<MenuDTO>>> GetFarXia([FromQuery]GetFarXiaCommand request)
        {
            return mediator.Send(request); 
        }
        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> UpdateMenu(UpdateMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<int>> DelMenu([FromQuery] DelMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询有没有子集
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<MenuDTO>>> GetMenuZi([FromQuery]GetMenuZiCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 菜单树形接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<TreeMenuDTO>>> GetMenuTree([FromQuery]GetMenuTreeCommand request)
        {
            return mediator.Send(request);
        }
    }
}
